﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Projektet.Model
{
    class NPCplayer : Player
    {
        private float _spawnInterval;

        private AiSpawnLogic _spawnLogic;        

        public NPCplayer(PlayerType playerType, EventListener eventListener, Vector2 startPos, AiSpawnLogic spawnLogic, int levelCount) 
        {
            _playerType = playerType;            
            _position = startPos;
            _spawnPosition = new Vector2(_position.X - 20, _position.Y);
            _castle = new Castle(_playerType, eventListener, _position);
            _spawnPosition.X += 23;
            _unitList.Add(_castle);

            _gold = 500;
            _goldIncome = 12 * (levelCount / 2);

            _spawnInterval = 7000f;
            _spawnLogic = spawnLogic;

            //_unitList.Add(new Pikeman(new Vector2(40f, 0f), -1f));
            //_unitList.Add(new Knight(new Vector2(40f, 0f), -1f));
        }

        public override void SpecificUpdate(GameTime gameTime)
        {
            _timeSinceSpawn += gameTime.ElapsedGameTime.Milliseconds;
            if(_timeSinceSpawn > _spawnInterval)
            {
                List<CombatUnit> suggestedList = _spawnLogic.GenerateSuggestedSpawnList(_position, _unitStats);
                //Console.WriteLine(suggestedList.Count);
                foreach(CombatUnit cU in suggestedList)
                {
                    if(_gold > 50)
                    {                    
                        switch(cU.GetType().Name)
                        {
                            case "Pikeman":
                                AddPikeman();
                                break;
                            case "Knight":
                                AddKnight();
                                break;
                            case "Archer":
                                AddArcher();
                                break;
                        }
                    }
                }
                _timeSinceSpawn = 0f;
            }
        }
    }
}
